<HTML>
  <HEAD>
    <TITLE>Charon Payment Deposit</TITLE>

    <LINK REL="stylesheet" TYPE="text/css" HREF="/charon.css"/>
    <SCRIPT TYPE="text/javascript" LANG="javascript" SRC="crypto.js"></SCRIPT>
    <SCRIPT TYPE="text/javascript" LANG="javascript">
      var ki;
      var pin;
      
      function keyresponse(x) {
        if(x.status != 200) {
	  alert("key bad status " + x.status);
          change('key-status');
        } else if(!/^\d+$/.test(x.responseText)) {
	  alert("key response '" + x.responseText + "'");
          change('key-response');
        } else {
	  pin = x.responseText;
          setId('pin', x.responseText);
	  document.getElementById("pinfield").value = pin;
	  change('key-ok');
        }
      }

      function start() {
      var o = new Dummy();
      o.setECB(function (x, y) {
            if(confirm("Error: " + x + "\nGo to help page for more information?\n(Note: help opens in new window, requires connection to remote site)"))
	    	    window.open("http://wiki.rcpt.to/wiki/index.php/Error_" + y, "MCX help");
      });
      try {
        if(ki == null) {
          o.sign(function (x) {
            ki = new XMLSerializer().serializeToString(x.response.responseXML.getElementsByTagName("KeyInfo")[0]);
            dispatchAll("/cgi-bin/key", 'key='+encodeURIComponent(ki), keyresponse);
          });
          o = null;
        } else {
          dispatchAll("/cgi-bin/key", 'key='+encodeURIComponent(ki), keyresponse);
        }
      } catch(e) {
	if('noMatchingCert' == e.message) {
	  change('sol-nmc');
	} else if('userCancel' == e.message) {
	  change('sol-uc');
	} else if('internalError' == e.message) {
	  change('sol-ie');
	} else {
	  change('sol-unknown');
	}
      }
     }

function setId(id, content) {
	var a = document.getElementById(id);
	a.innerHTML = content;
}

function change(x) {
	var n = document.getElementById(x);
	if(null == n) {
		alert("No element with id '" + x + "' found");
		return;
	}
	var p = n.parentNode;
	if(p.currentMessage) {
		var o = document.getElementById(p.currentMessage);
		o.className = "optionalMessage";
	}
	p.currentMessage = x;
	n.className = "currentMessage";
}

      function setup() {
      if(typeof(parent) && typeof(parent.prompt)) {
      document.getElementById("instructions").innerHTML = parent.instructions;
      }
      }

      function complete() {
      dispatchAll("/cgi-bin/auth", 'pin='+encodeURIComponent(pin), function (x) {
        if(x.status != 200) {
	  alert("auth bad status");
        } else {
	alert("auth retrieve ok");
	document.getElementById("authority").value = x.responseText;
	alert(x.responseText);
	document.getElementById("authpost").submit;
        }

      });
      }

      function retrieveAuthority() {
      var pin = document.getElementById("pinfield").value;
      dispatchAll("/cgi-bin/auth", 'pin='+encodeURIComponent(pin), function (x) {
        if(x.status != 200) {
	  alert("auth bad status " + x.status);
        }
	if(!x.responseXML) {
	  alert("Payment not confirmed! Please follow the instructions to pay the provider.");
	  return;
	}
	document.getElementById("authorityfield").value = x.responseText;
	document.getElementById("submitfield").disabled = false;
      });
      }
    </SCRIPT>
  </HEAD>
    <BODY onLoad="javascript:setup()">

      <DIV CLASS="main" STYLE="background-color: #eeeeff;">
      <H1>Prepaid Internet Access</H1>
      <P>You can deposit cash into your mikolaj.cx account directly by following the instructions below.</P>
      <FORM METHOD="POST" ACTION="http://mikolaj.cx/pkcs/RequestDrawdown" ID="authpost" TARGET="prepaid collect">
      <OL>
      <LI>First, you'll need to <INPUT TYPE="button" VALUE="get a PIN" onClick="javascript:start()"/></LI>
      <LI>Then, write your PIN down, and have it with you when you follow the below instructions to pay your deposit:
      <DIV STYLE="background-color: #c0ffc0;" ID="instructions">
      <I>Please wait, retrieving instructions for deposit</I>
      </DIV>
      </LI>
      <LI>Finally, enter your PIN into the box below, click <b>Confirm</b> to validate it, and then click the <b>Collect</b> button to complete the deposit (you can do this anytime, just make sure to write down your PIN).</LI>
      	<INPUT TYPE="hidden" ID="authorityfield" NAME="authority" />
	<LABEL FOR="pinfield">PIN: </LABEL>
	<INPUT TYPE="text" ID="pinfield" SIZE=5 NAME="pin" />
	<INPUT TYPE="button" VALUE="Confirm receipt" onClick="javascript:retrieveAuthority()"/>
	<INPUT TYPE="submit" ID="submitfield" VALUE="Collect deposit" DISABLED />
	<LI>Once that's completed, you can <A HREF="/" TARGET="_TOP">sign-on to access the Internet</A>.</LI>
      </OL>
      </FORM>

      <P>The money that you deposit can be used here for Internet access and anywhere else that accepts payment through mikolaj.cx.</P>

	<DIV CLASS="optionalMessage" ID="sol-nmc">
	You don't seem to have any identities loaded in your browser. What would you like to do? <BR/>
	<SPAN CLASS="center">
	<FORM>
	<INPUT TYPE="button" VALUE="Create an identity" onClick='javascript:window.open("http://mikolaj.cx/pkcs/key.html?close=1", "keygen")'/>
	  <INPUT TYPE="button" VALUE="Try again" onClick="javascript:start()"/>
	</FORM>
	</SPAN>
	</DIV>
	<DIV CLASS="optionalMessage" ID="sol-uc">
	Changed your mind? Second thoughts?
	What would you like to do? <BR/>
	<SPAN CLASS="center">
	<FORM>
	<INPUT TYPE="button" VALUE="Create an identity" onClick='javascript:window.open("http://mikolaj.cx/pkcs/key.html?close=1", "keygen")'/>
	<INPUT TYPE="button" VALUE="Try again" onClick="javascript:start()"/>
	</FORM>
	</SPAN>
	</DIV>
	<DIV CLASS="optionalMessage" ID="sol-ie">
	Uh-oh. Your browser's cryptographic engine has generated an internal error.
	What would you like to do? <BR/>
	<SPAN CLASS="center">
	<FORM>
	  <INPUT TYPE="button" VALUE="Try again" onClick="javascript:start()"/>
	  </FORM>
	</SPAN>
	</DIV>
	<DIV CLASS="optionalMessage" ID="sol-unknown">
	Uh-oh. Your browser's cryptographic engine has generated a mysterious error.
	What would you like to do? <BR/>
	<SPAN CLASS="center">
	<FORM>
	  <INPUT TYPE="button" VALUE="Try again" onClick="javascript:start()"/>
	  </FORM>
	</SPAN>
	</DIV>
	<DIV CLASS="optionalMessage" ID="key-status">
	<P>Oops! A mysterious error has occurred when submitting your key. Try again?</P>
	<SPAN CLASS="center">
	<FORM>
	  <INPUT TYPE="button" VALUE="Try again" onClick="javascript:start()"/>
	  </FORM>
	</SPAN>
	</DIV>
	<DIV CLASS="optionalMessage" ID="key-ok">
	<P><H3>Your PIN is <SPAN ID="pin">(Waiting)</SPAN>.</H3></P>
	<!--
	<FORM METHOD="POST" ACTION="http://mikolaj.cx/pkcs/RequestDrawdown" ID="authpost">
	<INPUT TYPE="hidden" ID="authority" NAME="authority" />
	  <INPUT TYPE="button" VALUE="Complete transfer" onClick="javascript:complete()"/>
	  <INPUT TYPE="submit" VALUE="go"/>
	</FORM>
	-->
	</DIV>

      </FORM>
      </DIV>
    </BODY>
</HTML>
